define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {
                 shop_id:0,
                 items:[],

                 type:1
                };
            },
            el: '#pageIndex',
            created: function() {
                this.fetchData();
            },
              mounted: function() {
                    
                    if (this.mounted == 1) {
                        return;
                    }
                    
                this.mounted = 1;
            },

            methods: {
                fetchData: function() {
                    var _this = this;

                    this.shop_id = this.$route.params.shop_id;

                    this.type = this.$route.params.type;
                    if( this.type==1){
                       app.setTitle('外卖分类');
                    }else if(this.type==2){
                       app.setTitle('到店扫码点餐分类');
                    }
                    this.init();
                   
                },
                getList:function(){
                  var that = this ;
                     that.loading = 1;
                     console.log(that.$route.params);
                    app.get("mall/tag/getByType", {
                      shop_id :  this.shop_id,
                      type:that.$route.params.type+",12",
                    }, function (res) {
                      that.loading = 0;
                      if (res.code != 200) {
                         app.alert(res.msg);
                         return ;
                      }
                      that.items = res.data; 
                    });
                },
                preview:function(){
                  var url ="";
                   var store_id = app.getStoreId();
                   if(this.type==1){
                       url = "/apps/app=takeout&store_id="+store_id+"#/"+this.shop_id;
                   }else{
                       url = "/apps/?app=eat_in_hall&store_id="+store_id+"#/shop_id/"+this.shop_id;
                   }
                   window.location.href = url;
                   
                },
                pageShow:function(){
                   var reload= app.getPageData("index",'reload');
                   // console.log(reload);
                   if(reload){
                     app.setPageData("index",{reload:0});
                     this.getList();
                   }
                    // var shop_id = app.getPageData("index",'shop_id');
                    // console.log(shop_id);
                    // if(shop_id>0){
                    //    app.setPageData("index",{shop_id:0});
                    //    this.shop_id = shop_id;
                    //    this.getList();
                    // }
                  
                },
                init:function(){
                    if( this.shop_id >0){
                       this.getList();
                     }else{
                       var that = this;
                       app.component("get_shop_id",{
                          success:function(shop_id){
                              that.shop_id = shop_id;
                              app.setPageData("index",{shop_id:shop_id});
                              // console.log("get_shop_id",shop_id);
                               
                              // that.$router.go(-1);
                              that.$router.push({name:"index",params:{shop_id:shop_id,type:that.type}});
                          }
                       });
                     }
                   
                },
                eat_in_hall_pay_setting:function(){
                   var user_info = app.getUserInfo();
                   var url ='https://www.bestsmartbee.com/mall-admin/mall-promotion/add?from=webapp&from_wx_app=1&token='+user_info.token+'&name=eat_in_hall_pay&shop_id='+this.shop_id;
                   window.location.href = url;
                },

                freight_setting:function(){
                   var user_info = app.getUserInfo();
                   var url ='https://www.bestsmartbee.com/mall-admin/mall_promotion/index?from=webapp&from_wx_app=1&token='+user_info.token+'&shop_id='+this.shop_id;
                   window.location.href = url;
                },
                shareUrl:function(){
                  var store_id = app.getStoreId();
                  var url ="";
                  if(this.type==1){
                       url = "/pages/takeout/?store_id="+store_id+"#/"+this.shop_id;
                   }else{
                       url = "/pages/eat_in_hall/?store_id="+store_id+"#/shop_id/"+this.shop_id;
                   }
                   var shareUrl = encodeURIComponent("https://wap.bestsmartbee.com"+url);
                  this.$router.push({name:"shareUrl",params:{url:shareUrl}});

                }
            
                


            }

        }).$mount('#app');
    };
    module.exports = controller;
});
